<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<%@include file="/common/head.jsp" %>

<c:set var="module" value="user"/>
<style type="text/css">
		.content{width: 200px; height: 40px;line-height:40px;margin-left:40px; color: #666;font-size:14px;  background-color: white; border-radius: 4px; margin-top: 30px; position: relative;border: none;}
	</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
		<form action="${ctx }/admin/user/save?id=${n.id }" id="detail-form" class="form-horizontal" method="post">
			<c:if test="${not empty type }">
			<input type="hidden" name="type" value="${type }" />
			</c:if>
			<c:if test="${empty type }">
            <div class="form-group">
                 <label class="col-sm-2 control-label">用户类型</label>
                 <div class="col-sm-10">
                 	${enum:detail('UserType', 'type', n.type) }
                 </div>
             </div>
             </c:if>
             
			<c:if test="${!seedUser }">
			<input type="hidden" name="parent.id" value="${parentId }" />
			</c:if>
			<div class="form-group">
                 <label class="col-sm-2 control-label">用户名</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="username" ${empty n.id ? '' : 'readonly' } value="${n.username }">
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">真实姓名</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="realName" value="${n.realName }" readonly>
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">昵称</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="nickName" value="${n.nickName }" readonly>
                 </div>
             </div>	
             	
			<div class="form-group">
                 <label class="col-sm-2 control-label">电话</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="mobile" value="${n.mobile }" readonly>
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">用户头像</label>
                 <div class="col-sm-10">
                 	  <%-- <img src="${n.headImage}" width="100px"/> --%>
                 	  <input type="hidden" name="headImage" id="headImage" value="${n.headImage }" onchange="xx()"/>
                 	 <div class="my-images" single="true" images="${n.headImage }" id="headImage1" field="headImage">
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">性别</label>
                 <div class="col-sm-10">
                 	<%-- <input type="text" class="form-control" name="sex" value="${enum:list('UserType', n.type)}"> --%>
                 	${enum:detail('Sex', 'sex', n.sex) }
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">省</label>
                 <div class="col-sm-10">
					<select name="province.id" class="form-control" id="provinceId">
						<c:forEach items="${provinces }" var="p">
						<option value="${p.id }" ${n.province.id eq p.id ? 'selected' : '' }>${p.name }</option>
						</c:forEach>
					</select>						                 	
                 </div>
                 
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">城市</label>
                 <div class="col-sm-10">
                 	<select name="city.id" class="form-control" id="cityId">
                 		<c:if test="${not empty(n.city.id) }">
                 		<option value="${n.city.id }">${n.city.name }</option>
                 		</c:if>
					</select>	
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">地区</label>
                 <div class="col-sm-10">
                 	<select name="district.id" class="form-control" id="districtId">
	                 	<c:if test="${not empty(n.district.id) }">
	                 		<option value="${n.district.id }">${n.district.name }</option>
                 		</c:if>
					</select>
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">地址</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="address" value="${n.address }">
                 </div>
             </div>	
			
			<div class="form-group">
                 <label class="col-sm-2 control-label">生日</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="birthday" value="<fmt:formatDate value='${n.birthday }' pattern='yyyy-MM-dd'/>" onclick="laydate({format: 'YYYY-MM-DD'})">
                 </div>
             </div>	
             
             <c:if test="${seedUser }">
	             <div class="form-group">
	                 <label class="col-sm-2 control-label">推荐人</label>
	                 <div class="col-sm-10">
	                 	<input type="hidden" id="parent-id" name="parent.id" value="${n.parent.id }" class="form-control">
	                 	<input type="text" class="form-control" id="parent-username" name="parent.username" value="${n.parent.username }" 
	                 		onclick="bring({
							                 	url:'${ctx}/admin/user/list',
							                 	name: 'username',
							                 	idInput: 'parent-id',
							                 	nameInput: 'parent-username'
							                 	})" />
	                 </div>
	             </div>	
             </c:if>
             <c:if test="${n.type == company }">
              <div class="form-group">
                 <label class="col-sm-2 control-label">公司名称</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="name" value="${c.name }">
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">公司注册地址</label>
                 <div class="col-sm-10">
            		<input type="text" class="form-control" name="registerAddress" value="${c.registerAddress }">
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">联系人</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="user.contactName" value="${c.user.contactName }">
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">联系人电话</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="user.mobile" value="${c.user.mobile }">
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">qq</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="user.QQ" value="${c.user.QQ}">
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">公司办公地址</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="officeAddress" value="${c.officeAddress }">
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">销售类型</label>
                 <div class="col-sm-10">
                 	 ${enum:detail('CompanySalesType', 'salesType', c.salesType) }
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">公司网址</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="webSite" value="${c.webSite }">
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">公司人数</label>
                 <div class="col-sm-10">
                 	 ${enum:detail('CompanyQuantity', 'quantity', c.quantity) }
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">公司行业</label>
                 <div class="col-sm-10">
                 	 ${enum:detail('CompanyIndustry', 'industry', c.industry) }
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">公司性质</label>
                 <div class="col-sm-10">
                 	 ${enum:detail('CompanyNature', 'nature', c.nature) }
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">备注</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="remark" value="${c.remark }">
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">证件上传</label>
                 <div class="col-sm-10">
		            <input type="hidden" name="images" id="images" value="${c.images }" />
                 	<div class="my-images" single="false" images="${c.images }" id="image2" field="images">
                 	</div>
                 </div>
             </div>
             </c:if>
             <c:if test="${n.type != company }">
             <div class="form-group">
             <label class="col-sm-2 control-label"></label>
             <input type="button" onclick="save()" class="content" style="text-align: center; color: #fff;background-color: #ED145B;" value="保存">
             </div> 
             </c:if>
		</form>
</div>

<%@include file="/common/foot.jsp" %>

<script>
$('select').attr('disabled','disabled');
function save() {
    	$.ajax({
    		url: "${ctx }/admin/user/save?id=${n.id }&type=${n.type}&sex=${n.sex}",
    		data: $('form').serialize(),
    		dataType: "json",
    		type: "post",
    		success: function(data) {
    			if (data.success) {
    				layer.msg('保存成功',{time: 1000, icon:6,shade: [0.5, '#f5f5f5']});
    			} else {
    				layer.msg('保存成功',{time: 1000, icon:6,shade: [0.5, '#f5f5f5']});
    			}
    		}
    		
    	});	
    }
$('#provinceId').change(function() {
	var provinceId = $(this).val();
	$('#cityId').html('');
	$('#districtId').html('');
	if (provinceId != '') {
		$.ajax({
			url: "${ctx}/admin/province/findArea?provinceId=" + provinceId,
			dataType: "json",
			success: function(array) {
				$('#cityId').append('<option value="">城市</option>');
				for (var i = 0; i < array.length; i++) {
					var obj = array[i];
					var option = '<option value="' + obj.id + '">' + obj.name + '</option>';
					$('#cityId').append(option);	
				}
			}
		});
	}
	
});

$('#cityId').change(function() {
	var cityId = $(this).val();
	if (cityId != '') {
		$.ajax({
			url: "${ctx}/admin/province/findArea?cityId=" + cityId,
			dataType: "json",
			success: function(array) {
				$('#districtId').append('<option value="">地区</option>');
				for (var i = 0; i < array.length; i++) {
					var obj = array[i];
					var option = '<option value="' + obj.id + '">' + obj.name + '</option>';
					$('#districtId').append(option);	
				}
			}
		});
	}
	load_filter_user();
});

$('#districtId').change(function() {
	load_filter_user();
});

$(document).ready(function() {
	init_images('headImage1');
	init_images('image2');
});
$(document).ready(function() {
	$('select').attr('disabled','disabled');
});
</script>
</body>
</html>
